import { IComposite } from "../interface/IComposite";
import { IBehaviour } from "../interface/IBehaviour";
import { BaseCondition } from "./BaseCondition";
import { BaseDecorator } from "./BaseDecorator";
import { EStatus } from "../common/EnumType";
import { BaseBehaviorNode } from "./BaseBehaviorNode";

export abstract class BaseComposite extends BaseBehaviorNode implements IComposite {
    protected children: Array<IBehaviour> = [];

    public addChild(child: IBehaviour): void {
        this.children.push(child);
    }

    public removeChild(child: IBehaviour) {
        let index = this.children.indexOf(child);
        if (index > -1) {
            this.children.splice(index, 1);
        }
    }

    public clearChild() {
        this.children = [];
    }

    public getChildren(): Array<IBehaviour> {
        return this.children;
    }

    public setChildren(behaviours: Array<IBehaviour>): void {
        this.children = behaviours;
    }

    public reset(): void {
        super.reset();
        for (let i = 0; i < this.children.length; i++) {
            this.children[i].reset();            
        }
    }
}
